package com.qingcloud.adminbackend.entity.role;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 用户身份表
 * </p>
 *
 * @author wangjinnan
 * @since 2018-12-19
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("sys_role")
public class SysRole extends Model<SysRole> {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "用户身份ID")
    private Integer id;

    /**
     * 身份名称
     */
    @ApiModelProperty(value = "身份名称")
    @TableField(value = "`name`")
    private String name;

    /**
     * 1网格化 2室内空气
     */
    @ApiModelProperty(value = "业务种类")
    private Integer businessType;

    @TableField(exist = false)
    @ApiModelProperty(hidden = true)
    private Integer roleType;

    /**
     * 身份描述描述
     */
    @ApiModelProperty(value = "描述", hidden = true)
    private String description;

    @TableField(value = "`order_num`")
    @ApiModelProperty(value = "排序序号")
    private Integer orderNum;

    @ApiModelProperty(value = "数据权限", hidden = true)
    private String dataFunction;

    @ApiModelProperty(value = "创建时间", hidden = true)
    private String createDt;

    @ApiModelProperty(value = "创建人", hidden = true)
    private String createBy;

    @ApiModelProperty(value = "修改时间", hidden = true)
    private String modifyDt;

    @ApiModelProperty(value = "修改人", hidden = true)
    private String modifyBy;

    @TableField(exist = false)
    @JSONField(serialize = false)
    @ApiModelProperty(hidden = true)
    private String funIds;

    @TableField(exist = false)
    @ApiModelProperty(value = "功能菜单列表")
    private List<String> funIdList;

    /**
     * 身份关联的功能ID列表
     */
    public List<String> getFunIdList() {
        if (StrUtil.isNotBlank(this.funIds)) {
            return Arrays.asList(this.funIds.split(","));
        }
        return Collections.emptyList();
    }
}
